var START_BTN_TAG = 1;
var StartLayer = cc.Layer.extend({
    ctor: function () {
        this._super();
        this.init();
    },
    init: function () {
        this._super();

        var winSize = cc.Director.sharedDirector.getWinSize();
        var centerPos = cc.p(winSize.width / 2, winSize.height / 2);

        var startImage = new cc.Sprite(res.Start_png);
        startImage.setPosition(centerPos.x, centerPos.y + 50);
        this.addChild(startImage);

        var starBtn = new cc.Sprite(res.StartBtn_png);
        starBtn.setPositionX(startImage.getPositionX());
        starBtn.setPositionY(startImage.getPositionY() - startImage.getContentSize().height / 2 - starBtn.getContentSize().height / 2);
        starBtn.setTag(START_BTN_TAG);
        this.addChild(starBtn);

        cc.eventManager.addListener({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: function (touch, event) {
                return this.isVisible();
            }.bind(this),
            onTouchEnded: function (touch, event) {
                var touchPos = touch.getLocation();

                var btnPos = starBtn.getPosition();
                var btnSize = starBtn.getContentSize();
                var minPos = cc.p(btnPos.x - btnSize.width/2 , btnPos.y - btnSize.height/2);
                var maxPos = cc.p(btnPos.x + btnSize.width/2 , btnPos.y + btnSize.height/2);
                if(touchPos.x < minPos.x) return;
                if(touchPos.y < minPos.y) return;
                if(touchPos.x > maxPos.x) return;
                if(touchPos.y > maxPos.y) return;
                this.setVisible(false);
                mainLayer.changeState(STATE_PLAY);
            }.bind(this)
        }, this);
    }
});